﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.Environment.Extensions;

namespace FruitCake.ContactPage.Models
{
    [OrchardFeature("FruitCake.ContactPage")]
    public class ReasonRule
    {
        /// <summary>
        /// Format: text[|ToList][|CcList][|BccList]
        /// </summary>
        public static ReasonRule Create(int index, string line)
        {          
            try
            {
                if(string.IsNullOrWhiteSpace(line)) return null;

                ReasonRule rule = new ReasonRule();

                string[] parts = line.Split('|');

                rule.Index = index.ToString();
                rule.Text = parts[0];

                if (parts.Count() > 1) rule.ToList = parts[1];
                if (parts.Count() > 2) rule.CcList = parts[2];
                if (parts.Count() > 3) rule.BccList = parts[3];

                return rule;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
       
        protected ReasonRule()
        {
            Index = "0";
            Text = "";
            ToList = "";
            CcList = "";
            BccList = "";
        }

        public string Index { get; protected set; }
        public string Text { get; protected set; }
        public string ToList { get; protected set; }
        public string CcList { get; protected set; }
        public string BccList { get; protected set; }
    }
}